//Eventos e inicializaciones en alimentos_alimentos.js
var arrModels  = new Array();
var arrTables  = new Array();
var arrDetails = new Array();

var alimentoModel = undefined;
var alimentoTableUI = undefined;
var alimentoDetailUI = undefined;

var pendingLoads = 0;

function startLoad(){
    pendingLoads++;
}

function endLoad(){
    pendingLoads--;
    
    if(pendingLoads < 0){
        pendingLoads = 0;
    }

}

function initGruposAlimentos(){
    $( "#accordion_alimentos" ).accordion({
        autoHeight: false,
        navigation: true,
        create: accordionCreate,
        change: accordionChange
    });

    crearDialogo();
    $("#content").css("overflow-x", "hidden");
    $("#content").css("overflow-y", "hidden");
}

function accordionCreate(event, ui){
    $(this).find("a").each(function(){
        var elemId = new String($(this).attr("id"));
        var id = elemId.substr(3, elemId.length);

        arrModels[id] = getAlimentoModel(id);
    });

    //$(this).accordion("activate", $(this).find("h5:last"));
    var elemId = new String($(this).find("a:first").attr("id"));
    var id = elemId.substr(3, elemId.length);
    arrTables[id]  = getAlimentoTableUI(id, arrModels[id]);
    arrDetails[id] = getAlimentoDetailUI(id, arrModels[id], arrTables[id]);
}

function accordionChange(event, ui){
     var elemId = new String($(ui.newHeader).find("a:first").attr("id"));
     var id = elemId.substr(3, elemId.length);

     if(arrTables[id] == undefined){
         arrTables[id]  = getAlimentoTableUI(id, arrModels[id]);
         arrDetails[id] = getAlimentoDetailUI(id, arrModels[id], arrTables[id]);
     }
}
